home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dbase
/
lib19.zip
/
DATES.PRG
< prev
next >
Wrap
Text File
|
1992-06-25
|
36KB
|
924 lines
*-------------------------------------------------------------------------------
*-- Program...: DATES.PRG
*-- Programmer: Ken Mayer (KENMAYER)
*-- Date......: 06/25/1992
*-- Notes.....: These are the date functions/procedures I felt were not as
*-- commonly used as those left behind in PROC.PRG. See README.TXT
*-- for details on the use of this library file.
*-------------------------------------------------------------------------------
FUNCTION DateText3
*-------------------------------------------------------------------------------
*-- Programmer..: Miriam Liskin
*-- Date........: 03/02/1992
*-- Notes.......: Display date in format Month, year
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: 05/21/1991 - original function.
*-- 03/02/1992 - This one's Douglas P. Saine's (XRED) invention.
*-- In his words: "I just removed the middle part looking for
*-- the day. For the things I do, I only need the month and
*-- year. (I work for a defense contracter, accuracy of dates
*-- has never been of great concern. <G>)"
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: DateText3(<dDate>)
*-- Example.....: ? DateText3(date())
*-- Returns.....: July, 1991
*-- Parameters..: dDate = date to be converted
*-------------------------------------------------------------------------------
parameters dDate
RETURN cmonth(dDate)+", "+str(year(dDate),4)
*-- EoF: DateText3()
FUNCTION Age2
*-------------------------------------------------------------------------------
*-- Programmer..: Martin Leon (HMAN)
*-- Date........: 04/22/1992
*-- Notes.......: Returns number of full years between two dates, which is
*-- age of a person born on the first date as of the second.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: 10/23/1991 - original function.
*-- 04/22/1992 -- Description modified, parameters changed by
*-- Jay Parsons (JPARSONS).
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: Age2(<d1>,<d2>)
*-- Example.....: ? "Joe was "+ltrim(str(age2(dBDay,{10/16/85})))+;
*-- " on the day of ..."
*-- Returns.....: Numeric value in years
*-- Parameters..: d1 = first date, such as date of birth
*-- d2 = second date, when age is wanted
*-------------------------------------------------------------------------------
parameters d1, d2
private nYears
nYears = year(d2) - year(d1)
do case
case month(d1) > month(d2)
nYears = nYears - 1
case month(d1) = month(d2)
if day(d1) > day(d2)
nYears = nYears - 1
endif
endcase
RETURN nYears
*-- EoF: Age2()
FUNCTION IsLeap
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 01/13/1992
*-- Notes.......: Is the year given a Leap Year? Year given must be after 1500
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: 11/08/1991 - original function.
*-- 01/13/1992 -- updated to handle two digit OR four digit year.
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: IsLeap(<nYear>)
*-- Example.....: IsLeap(91)
*-- Returns.....: Logical (.t./.f.)
*-- Parameters..: nYear = Numeric form of year -- last two digits (i.e., 91),
*-- or all four digits (i.e., 1991)
*-------------------------------------------------------------------------------
parameter nYear
private lReturn
*-- deal with two digit year ...
if nYear < 100
nYear = nYear + 100 * int(year(date())/100)
endif
lReturn = mod(iif(mod(nYear,100)=0,nYear/100,nYear),4)=0
RETURN lReturn
*-- EoF: IsLeap()
FUNCTION Annivrsry
*-------------------------------------------------------------------------------
*-- Programmer..: David Love (DAVIDLOVE) and Jay Parsons (JPARSONS)
*-- Date........: 11/10/1991
*-- Notes.......: Checks to see if an anniversary date falls within a range of
*-- dates (handy for mailings for organizations, checking to see
*-- if someone's birthday falls within certain dates, etc.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: None
*-- Calls.......: AGE2() Function in DATES.PRG
*-- Called by...: Any
*-- Usage.......: Annivrsry(<dTest>,<dBegin>,<dEnd>)
*-- Example.....: if Annivrsry(dBDay,{03/01/91},{03/31/91})
*-- *-- do something
*-- endif
*-- Returns.....: .t. if a date (dTest) falls within the period beginning at
*-- dBegin or ending at dEnd, inclusive. .F. for any other
*-- occurance, including invalid ranges or blank dates.
*-- Parameters..: dTest = Date being tested for ...
*-- dBegin = Beginning of range
*-- dEnd = End of range
*-------------------------------------------------------------------------------
parameters dTest, dBegin, dEnd
private nYears
nYears = 0
if dBegin <= dEnd .AND. dTest <= dEnd && will be false if blank
nYears = age2(dTest,dEnd) - iif(dTest < dBegin,age2(dTest,dBegin-1),0)
endif
RETURN nYears > 0
*-- EoF: Annivrsry()
FUNCTION AddMonths
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 11/10/1991
*-- Notes.......: Finds same day as given date N months ahead.
*-- This function will return the first day of the following
*-- month if there is no date in the month otherwise returned
*-- and nMonths is positive, or the last day of the month if
*-- nMonths is negative. That is, a call with {01/31/91}
*-- (January 31, 1991) and 1 would yield March 1, there being
*-- no February 31.
*-- Do not use this function successively to find first the
*-- date one month ahead, then the date one month beyond that.
*-- Instead, to find the date two months ahead from the original
*-- date, call this function with the original date and
*-- nMonths = 2. Otherwise, in the example, you'll get April 1
*-- the second time rather than the correct March 31.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: AddMonths(<dDate>,<nMonths>)
*-- Example.....: ?AddMonths({01/01/91},1)
*-- Returns.....: Date
*-- Parameters..: dDate = Date being tested for ...
*-- dMonths = Number of months "ahead"
*-------------------------------------------------------------------------------
parameters dDate, nMonths
private dNew, dTest,dReturn
dNew = dDate - day(dDate)+ 15 + 30.436875 * nMonths && middle of month
dTest = dNew - day(dNew) + day(dDate)
dReturn = iif(month(dTest) = month(dNew),dTest, ;
dTest - day(dTest) + iif(nMonths > 0, 1, 0))
RETURN dReturn
*-- EoF: AddMonths()
FUNCTION AddYears
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 11/14/1991
*-- Notes.......: Finds same day as given date N years ahead.
*-- Using this function dBASE IV will take care of converting
*-- February 29 to March 1 if moving from a leap to a non-leap
*-- year. However, neither may be used backwards (negative
*-- value of nYears) since the date a year before February 29,
*-- 1992 will be returned as March 1, 1991, not February 28, 1991.
*-- If you must move back, either check explicitly for February 29
*-- as the original date or add code as in the addmonths()
*-- function to test for the date returned being of a different
*-- month than the original and, if it is, to subtract its day().
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: 11/10/1991 - original function.
*-- 11/14/1991 - Ken Mayer - expanded out